package com.yunxi.service.localService.impl.otd;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunxi.core.service.ServiceImplPlus;
import com.yunxi.core.util.BeanTools;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.dao.otd.OtdNodeConfigMapper;
import com.yunxi.model.otd.OtdNodeConfig;
import com.yunxi.otd.pojo.OtdNodeConfigEditVO;
import com.yunxi.otd.pojo.OtdNodeConfigVO;
import com.yunxi.service.localService.otd.OtdNodeConfigService;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

/**
 * <p>
 * OTD节点设置 服务实现类
 * </p>
 *
 * @author XUQI
 * @since 2019-08-22
 */
@Service
public class OtdNodeConfigServiceImpl extends ServiceImplPlus<OtdNodeConfigMapper, OtdNodeConfig> implements
    OtdNodeConfigService {

    /**
     * 查询所有节点
     *
     * @return ApiResult
     */
    @Override
    public ApiResult queryAllNode(Map<String, Object> map) {
        List list = baseMapper.queryByList(map);
        if (CollectionUtils.isEmpty(list)) {
            ResponseUtil.ok();
        }
        return ResponseUtil.ok(BeanTools.copyListToList(list, OtdNodeConfigVO.class));
    }


    /**
     * 设置时长
     *
     * @param editVO editVO
     * @return ApiResult
     */
    @Override
    public ApiResult update(OtdNodeConfigEditVO editVO) {
        OtdNodeConfig otdNodeConfig = new OtdNodeConfig();
        otdNodeConfig.setDayNum(editVO.getDayNum()); // 天数
        otdNodeConfig.setHourNum(editVO.getHourNum()); // 小时数
        // 条件 节点Code
        LambdaQueryWrapper<OtdNodeConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OtdNodeConfig::getNodeCode, editVO.getNodeCode());
        baseMapper.update(otdNodeConfig, wrapper);
        return ResponseUtil.ok();
    }
}
